// pages/index/index.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 1,
        bannerData: null,
        newRecomData: null,
        userInfo: null
    },
    onLoad() {
        // banner数据
        wx.request({
            url: 'http://www.kangliuyong.com:10002/banner',
            method: 'GET',
            data: {
                appkey: app.globalData.appkey
            },
            success: (res) => {
                console.log(res);
                this.setData({
                    bannerData: res.data.result
                })
            }
        })
        // 最新推荐
        wx.request({
            url: 'http://www.kangliuyong.com:10002/typeProducts',
            method: 'GET',
            data: {
                appkey: app.globalData.appkey,
                key: 'isHot',
                value: 'coffee'
            },
            success: (res) => {
                console.log(res);
                this.setData({
                    newRecomData: res.data.result
                })
            }
        })
    },
    onShow() {
        let token = wx.getStorageSync('token')
        console.log(app.globalData.token);
        console.log(token);
        this.setData({
            userInfo: app.globalData.userInfo
        })
    },
    pushDetail(e) {
        let pid = e.currentTarget.dataset.pid
        console.log(pid);
        wx.navigateTo({
            url: '/pages/detail/detail?pid=' + pid,
        })
    },
    pushSearch() {
        wx.navigateTo({
            url: '/pages/search/search',
        })
    }
})